package com.bym.controller;

import com.alibaba.fastjson.JSON;
import com.bym.rocket.RocketMQProducer;
import com.bym.vo.BymMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h1>SpringBoot 集成 RocketMQ</h1>
 */
@Slf4j
@RestController
@RequestMapping("/rocket-mq")
public class RocketMQController {

    private static final BymMessage rocketMQMessage =
            new BymMessage(1, "Bym-Study-RocketMQ-In-SpringBoot");

    @Autowired
    private RocketMQProducer rocketMQProducer;

    @GetMapping("/message-with-value")
    public void sendMessageWithValue() {
        rocketMQProducer.sendMessageWithValue(JSON.toJSONString(rocketMQMessage));
    }

    @GetMapping("/message-with-key")
    public void sendMessageWithKey() {
        rocketMQProducer.sendMessageWithKey("Bym", JSON.toJSONString(rocketMQMessage));
    }

    @GetMapping("/message-with-tag")
    public void sendMessageWithTag() {
        rocketMQProducer.sendMessageWithTag("bym", JSON.toJSONString(rocketMQMessage));
    }

    @GetMapping("/message-with-all")
    public void sendMessageWithAll() {
        rocketMQProducer.sendMessageWithAll("Bym", "bym", JSON.toJSONString(rocketMQMessage));
    }
}
